<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>闭包的作用</title>
</head>

<body>
  <script>
    // 作用：延长作用域
    function fn() {
      a = 123;
      return function () {
        console.log(a);
      }
    }
    var f = fn();
    // 相当于： var f = function () { console.log(a); }
    f();  //123
  </script>
</body>

</html>